library(pwr)

# note: this code picks up on line 172 of "main_tables.R", with data and models loaded
# see vignette: https://cran.r-project.org/web/packages/pwr/vignettes/pwr-vignette.html
#


# mod1
u <- mod1$p - 1

v <- mod1$N - u - 1

# check mod1 for R-squared as denominator. use partial R-squared from mod1 Table 1. (not here) in numerator.
summary(mod1)

f2 <- .0026/(1-(.9435+.0026))

pwr.f2.test(u=u,v=v,f2=f2)

# mod4
u <- mod4$p - 1

v <- mod4$N - u - 1

# check mod4 for R-squared as denominator. use partial R-squared from mod1 Table 1. (not here) in numerator.
summary(mod4)

f2 <- .0026/(1-(.973+.0026))

pwr.f2.test(u=u,v=v,f2=f2)


# mod5
u <- mod5$p - 1

v <- mod5$N - u - 1

# check mod5 for R-squared as denominator. use partial R-squared from mod1 Table 1. (not here) in numerator.
summary(mod5)

f2 <- .0026/(1-(.9838+.0026))

pwr.f2.test(u=u,v=v,f2=f2)


# mod6
u <- mod6$p - 1

v <- mod6$N - u - 1

# check mod6 for R-squared as denominator. use partial R-squared from mod1 Table 1. (not here) in numerator.
summary(mod6)

f2 <- .0026/(1-(.9941+.0026))

pwr.f2.test(u=u,v=v,f2=f2)


### check with revised expectation

# mod1
u <- mod1$p - 1

v <- mod1$N - u - 1

# check mod1 for R-squared as denominator. use partial R-squared of one percent.
summary(mod1)

f2 <- .01/(1-(.9435+.01))

pwr.f2.test(u=u,v=v,f2=f2)

# mod4
u <- mod4$p - 1

v <- mod4$N - u - 1

# check mod4 for R-squared as denominator. use partial R-squared of one percent.
summary(mod4)

f2 <- .01/(1-(.973+.01))

pwr.f2.test(u=u,v=v,f2=f2)


# mod5
u <- mod5$p - 1

v <- mod5$N - u - 1

# check mod5 for R-squared as denominator. use partial R-squared of one percent.
summary(mod5)

f2 <- .01/(1-(.9838+.01))

pwr.f2.test(u=u,v=v,f2=f2)


# mod6
u <- mod6$p - 1

v <- mod6$N - u - 1

# check mod6 for R-squared as denominator (note, must revise this down so that f2 is positive). use partial R-squared of one percent.
summary(mod6)

f2 <- .01/(1-(.9899+.01))

pwr.f2.test(u=u,v=v,f2=f2)
